package com.life.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

import com.life.constants.Constants;

public class ReportsPanel extends JPanel
{
    WidgetRegistry widgetRegistry = WidgetRegistry.getInstance();
    
    public ReportsPanel()
    {
	init();
    }
    
    
    protected void init()
    {
	this.setLayout(null);
	TitledBorder border = new TitledBorder("");
	JPanel statisticsPanel = new JPanel();
	statisticsPanel.setBorder(border);
	statisticsPanel.setBounds(0,15,275,75);
	statisticsPanel.setLayout(null);
	this.add(statisticsPanel);
	
	
	
	JButton generateStatsButton = new JButton("Generate");
	generateStatsButton.setBounds(150,10,95,55);
	statisticsPanel.add(generateStatsButton);
	
	JProgressBar progressBar = new JProgressBar();
	progressBar.setBounds(25,20,100,35);
	progressBar.setVisible(true);
	statisticsPanel.add(progressBar);
	
	JTabbedPane resultsPane = new JTabbedPane();
	resultsPane.setBounds(110,90,280,600);

	StatisticsPanel statPanel = new StatisticsPanel();
	statPanel.setBounds(0,90,290,600);
	statPanel.setVisible(false);
	
	this.add(statPanel);
	
	widgetRegistry.put(Constants.GENERATE_STATISTICS_WIDGET,generateStatsButton);
	widgetRegistry.put(Constants.GENERATE_PROGRESS_BAR,progressBar);
	widgetRegistry.put(Constants.GENERATE_TABBED_PANE_WIDGET,statPanel);
	
	JLabel pauseLabel = new JLabel("Simulation must be paused to run reports");
	pauseLabel.setBounds(30,0,300,15);
	this.add(pauseLabel);
	
	resultsPane.setVisible(false);
    }
    
    class StatisticsPanel extends JPanel
    {
		
	
	public StatisticsPanel()
	{
	   init();    
	}
	
	public void init()
	{
	    this.setLayout(null);
	    JPanel topPanel = new JPanel();
	    topPanel.setLayout(null);
	    topPanel.setBounds(0,0,270,175);
	    this.add(topPanel);
	    TitledBorder results = new TitledBorder("Results");
	    topPanel.setBorder(results);
	     
	     
	     JList list = new JList();
	     widgetRegistry.put(Constants.STATISTICS_RESULTS_LIST, list);
	     
	     JScrollPane scrollPane = new JScrollPane(list);
	     scrollPane.setBounds(10,20,250,140);
	     topPanel.add(scrollPane);
	     
	     GraphPanel panel = new GraphPanel();
	     panel.setBounds(0,280,270,100);
	     this.add(panel);
	     
	     JLabel cellId = new JLabel("Mouse-over cells to see individual info");
    	     cellId.setBounds(30,110,30,15);
	     this.add(cellId);
	     
	     CellInfoPanel cellPanel = new CellInfoPanel();
	     cellPanel.setBounds(0,175,270,100);
	     this.add(cellPanel);
	     
	     ClusterPanel clusterPanel = new ClusterPanel();
	     clusterPanel.setBounds(0,380,270,60);
	     this.add(clusterPanel);
	}
    }
    
    class GraphPanel extends JPanel
    {
	
	public GraphPanel()
	{
	    init();
	}
	
	public void init()
	{
	    this.setLayout(null);
	    TitledBorder border = new TitledBorder("Graphs");
	    this.setBorder(border);
	    
	    JButton showGraphs = new JButton("Show Graph");
	    showGraphs.setBounds(150,20,95,55);
	    this.add(showGraphs);
	    
	    JList graphOptions = new JList(new String[]{"Births per generations","Deaths per generation","Lifes"});
	    graphOptions.setSelectedIndex(0);
	    JScrollPane graphOptionsScrollPane = new JScrollPane(graphOptions);	    
	    graphOptionsScrollPane.setBounds(10,20,130,70);
	    
	    this.add(graphOptionsScrollPane);
	    
	    
	    widgetRegistry.put(Constants.SHOW_GRAPH_WIDGET,showGraphs);
	    widgetRegistry.put(Constants.GRAPH_OPTIONS_WIDGET,graphOptions);
	    
	}
    }
    
    class CellInfoPanel extends JPanel
    {
	public CellInfoPanel()
	{
	    init();
	}
	
	public void init()
	{
	  this.setLayout(null);
	  
	  TitledBorder border = new TitledBorder("Cell Info");
	  this.setBorder(border);
	  
	  JList cellInfoList = new JList(new String[]{"Mouse over cells for info"});
	  
	  widgetRegistry.put(Constants.CELL_INFO_WIDGET,cellInfoList);
	  
	  JScrollPane cellInfoScrollPane = new JScrollPane(cellInfoList);
	  cellInfoScrollPane.setBounds(10,20,250,70);
	  this.add(cellInfoScrollPane);
	    
	    
	}
    }
    
    class ClusterPanel extends JPanel
    {
	public ClusterPanel()
	{
	    init();
	}
	
	public void init()
	{
	    TitledBorder border = new TitledBorder("Clusters");
	    this.setBorder(border);
	    
	    this.setLayout(new BorderLayout());
	    
	    JCheckBox checkBox = new JCheckBox("Highlight Clusters");
	    this.add(checkBox,BorderLayout.CENTER);
	    
	    widgetRegistry.put(Constants.HIGHLIGHT_CLUSTERS_WIDGET,checkBox);
	}
    }
    
    }

